﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WcsApi.Models
{
    public class Result<T>
    {
        /// <summary>
        /// 成功返回任务编号ID
        /// </summary>
        public List<T> resultData { get; set; }

        /// <summary>
        /// 成功或者失败码  0:代表成功 1:代表失败
        /// </summary>
        public int code { get; set; }

        /// <summary>
        /// 信息说明
        /// </summary>
        public string message { get; set; }

        public static Result<T> jsonResult(List<T> data, int code, string msg)
        {
            Result<T> result = new Result<T> 
            { 
                code = code,
                message = msg,
                resultData = data
            };
            return result;
        }

        public static Result<T> success()
        {
            return jsonResult(default, 0, "SUCCESS");
        }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Result<T> success(List<T> data)
        {
            return jsonResult(data, 0, "SUCCESS");
        }


        public static Result<T> error(String msg)
        {
            return jsonResult(default, 500, msg);
        }
    }
}